//
//  PersonalVipHeadVIewCell.m
//  ChatForHot
//
//  Created by wr on 2018/10/11.
//  Copyright © 2018年 FLY. All rights reserved.
//

#import "PersonalVipHeadVIewCell.h"
#import "PersonalVipViewModel.h"
#import "PersonalVipInfoModel.h"

@interface PersonalVipHeadVIewCell ()

@property (nonatomic, strong) UIImageView *HOTCHATbackImageView;
@property (nonatomic, strong) UIImageView *HOTCHATselectedMark;
@property (nonatomic, strong) UILabel *HOTCHATtimeLabel;
@property (nonatomic, strong) UILabel *HOTCHATproductType;
@property (nonatomic, strong) UILabel *HOTCHATpriceLable;
@property (nonatomic, strong) UILabel *HOTCHAToffsetLabel;
@end

@implementation PersonalVipHeadVIewCell

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self HOTCHATdidInitialized];
    }
    return self;
}

- (void)HOTCHATdidInitialized {
    self.HOTCHATbackImageView = [[UIImageView alloc] init];
    [self.contentView addSubview:self.HOTCHATbackImageView];
    
    self.HOTCHATselectedMark = [[UIImageView alloc] init];
    [self.HOTCHATselectedMark setImage:[UIImage imageNamed:@"p_vip_selected_ic"]];
    [self.HOTCHATbackImageView addSubview:self.HOTCHATselectedMark];
    
    self.HOTCHATtimeLabel = [[UILabel alloc] init];
    self.HOTCHATtimeLabel.font = [UIFont fontWithName:@"PingFangSC-Medium" size:32];
    self.HOTCHATtimeLabel.textColor = [UIColor colorFromHexString:@"#3E3E3E"];
    [self.contentView addSubview:self.HOTCHATtimeLabel];
    
    self.HOTCHATproductType = [[UILabel alloc] init];
    self.HOTCHATproductType.numberOfLines = 0;
    self.HOTCHATproductType.font = [UIFont systemFontOfSize:18];
    self.HOTCHATproductType.textColor = [UIColor colorFromHexString:@"#3E3E3E"];
    [self.contentView addSubview:self.HOTCHATproductType];
    
    self.HOTCHATpriceLable = [[UILabel alloc] init];
    self.HOTCHATpriceLable.font = [UIFont systemFontOfSize:15];
    self.HOTCHATpriceLable.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:self.HOTCHATpriceLable];
    
    self.HOTCHAToffsetLabel = [[UILabel alloc] init];
    self.HOTCHAToffsetLabel.layer.masksToBounds = YES;
    self.HOTCHAToffsetLabel.layer.cornerRadius = 30/2;
    self.HOTCHAToffsetLabel.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:self.HOTCHAToffsetLabel];
}

- (void)HOTCHATbind:(PersonalVipInfoModel *)model {
    if (model == nil) {
        return;
    }
    
    self.HOTCHATtimeLabel.text = model.duration;
    self.HOTCHATproductType.text = model.unit;
    self.HOTCHATpriceLable.text = [NSString stringWithFormat:@"$%@",model.price];
    self.HOTCHAToffsetLabel.text = model.offset;
    
    self.HOTCHATselectedMark.hidden = !model.selected;
    if (model.selected) {
        [self.HOTCHATbackImageView setImage:[UIImage imageNamed:@"p_vip_selected"]];
        self.HOTCHATpriceLable.textColor = [UIColor colorFromHexString:@"#FF9300"];
        
        self.HOTCHAToffsetLabel.textColor = [UIColor colorFromHexString:@"FFFFFF"];
        self.HOTCHAToffsetLabel.backgroundColor = [UIColor colorFromHexString:@"#8123FF"];
    }else {
        [self.HOTCHATbackImageView setImage:[UIImage imageNamed:@"p_vip_normal"]];
        self.HOTCHATpriceLable.textColor = [UIColor colorFromHexString:@"111111"];
        
        self.HOTCHAToffsetLabel.textColor = [UIColor colorFromHexString:@"#111111"];
        self.HOTCHAToffsetLabel.backgroundColor = [UIColor colorFromHexString:@"FFFFFF"];
        self.HOTCHAToffsetLabel.layer.borderColor = [UIColor colorFromHexString:@"111111"].CGColor;
        self.HOTCHAToffsetLabel.layer.borderWidth = 1.0;
    }
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.HOTCHATbackImageView.size = CGSizeMake((kScreenWidth - 10 * 4) / 3, 154);
    self.HOTCHATbackImageView.centerX = self.contentView.centerX;
    self.HOTCHATbackImageView.centerY = self.contentView.centerY;
    
    self.HOTCHATselectedMark.size = CGSizeMake(16, 16);
    self.HOTCHATselectedMark.top = 0;
    self.HOTCHATselectedMark.left = ((kScreenWidth - 10 * 4) / 3) - 10 - 10;
    
    self.HOTCHATtimeLabel.size = CGSizeMake(18, 45);
    self.HOTCHATtimeLabel.top = 20;
    self.HOTCHATtimeLabel.left = 25;
    
    self.HOTCHATproductType.size = CGSizeMake(100, 28);
    self.HOTCHATproductType.centerY = self.HOTCHATtimeLabel.centerY;
    self.HOTCHATproductType.left = self.HOTCHATtimeLabel.right + 5;
    
    self.HOTCHATpriceLable.size = CGSizeMake(60, 21);
    self.HOTCHATpriceLable.centerX = self.HOTCHATbackImageView.centerX;
    self.HOTCHATpriceLable.top = self.HOTCHATproductType.bottom + 10;
    
    self.HOTCHAToffsetLabel.size = CGSizeMake(92, 30);
    self.HOTCHAToffsetLabel.centerX = self.contentView.centerX;
    self.HOTCHAToffsetLabel.top = self.HOTCHATpriceLable.bottom + 15;
}
@end
